using System.IO;
using Microsoft.SharePoint;

namespace My.SharePoint.STSADM.Commands.SPValidators
{
    public interface ISPValidator
    {
        bool Validate(string str);
    }


    internal class SPValidator : ISPValidator
    {
        public virtual bool Validate(string str)
        {
            return true;
        }
    }


    internal class SPDirectoryExistsAndValidFileNameValidator : SPNonEmptyValidator
    {
        public override bool Validate(string str)
        {
            if (base.Validate(str))
            {
                try
                {
                    FileInfo info = new FileInfo(str);
                    if (info.Directory.Exists)
                    {
                        if (info.Name.EndsWith("\\") || info.Name.EndsWith("/"))
                            throw new SPException(SPResource.GetString("StsadmReqFileName", new object[0]));

                        return true;
                    }
                    else 
                        throw new DirectoryNotFoundException();
                }
                catch
                {
                    return false;
                }
            }
            return false;
        }
    }


}
